﻿using System.Windows.Forms;
using GeekShop.Tools;

namespace GeekShop
{
    public class MenuItem : MenuObject
    {
        #region Events
        public event ActiveToolChangedHandler ToolSelected;
        #endregion

        #region Fields
        private ITool tool;
        #endregion

        #region Properties
        public ITool Tool
        {
            get { return this.tool; }
            set
            {
                this.tool = value;
                this.IsTool = value != null;
            }
        }
        public bool IsTool
        {
            set
            {
                if (value)
                {
                    System.EventHandler handler = new System.EventHandler(Tool_Click);
                    this.MenuItem.Click += handler;
                    this.ToolItem.Click += handler;
                }
            }
        }
        #endregion

        void Tool_Click(object sender, System.EventArgs e)
        {
            this.ToolSelected(this, new ToolEventArgs(){ ActiveTool = this.Tool });
            this.Image = this.tool.Icon;
        }
        
        #region Constructors
        public MenuItem()
        {
            this.MenuItem = new ToolStripMenuItem() { Visible = true };
            this.ToolItem = new ToolStripButton() { Visible = true };
        }
        #endregion
    }
}
